import java.util.Scanner;

public class StringTests4 {
    public static void main(String[] args) {
        //键盘录入一个数组
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数组长度：");
        int len = sc.nextInt();
        int[] arr = new int[len];
        System.out.println("请输入数组元素：");
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个元素：");
            arr[i] = sc.nextInt();
        }
        String a = arrToString(arr);
        System.out.println(a);

    }
    /*=========================方法区==============================*/
    public static String arrToString(int[] arr){
        String result = "[";
            if(arr == null){return null;}
            if(arr.length == 0){return "[]";}

        for (int i = 0;i < arr.length;i++){
            if(i == arr.length-1){
                result = result + arr[i]+"]";
                break;
            }
            result = result + arr[i]+",";
        }
        return result;
    }
}
